package com.li.sssp.aspect;

import java.util.Date;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class TestAspect {

//	@Before("execution(* com.li.sssp.server.ActorService.*(..))")
//	//@Before("execution(public com.li.sssp.handle.* )")
//	public void testAspect(){
//		System.out.println("任何的开始begin");
//	}
//	@After("execution(* com.li.sssp.server.ActorService.*(..))")
//	public void afterMethod(JoinPoint joinPoint){
//		String methodName=joinPoint.getSignature().getName();
//		System.out.println("The method"+methodName+"ends");
//	}
//	
//	@AfterReturning(value="execution(* com.li.sssp.server.ActorService.*(..))",returning="result")
//	public void returnMethod(JoinPoint joinPoint,Object result){
//		System.out.println("This is AfterReturning"+result);
//	}
	
	@Around(value="execution(* com.li.sssp.server.RoleService.*(..))")
	public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable{
		
		Object obj = null;
		try {
			// before
			System.out.println("This is Before:"+joinPoint.getSignature().getName()+"  "+new Date());
			 obj = joinPoint.proceed();
			 Object[] args=joinPoint.getArgs();
			 for (Object object : args) {
				System.out.println(object.toString());
			}
			//	AfterReturning
			System.out.println("This is AfterReturning Result is:"+obj+"  "+new Date());

		} catch (Exception e) {
			// TODO: handle exception
			//	AfterThrowing
			
		}
		//	After
		
		System.out.println("This is After "+new Date());
		return obj;
	}
}
